<template>
  <!--
          作者：luoyiming
          时间：2019-10-25
          描述：订单-行程订单
      -->
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="起点或终点">
          <el-input v-model="formInline.order_no" placeholder="请输入起点或终点"></el-input>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option label="未支付" value="0"></el-option>
            <el-option label="已支付" value="1"></el-option>
            <el-option label="退单中" value="3"></el-option>
            <el-option label="已取消" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="接单状态">
          <el-select v-model="formInline.owner_status" placeholder="请选择">
            <el-option label="未接单" value="-1"></el-option>
            <el-option label="未支付" value="0"></el-option>
            <el-option label="已支付" value="1"></el-option>
            <el-option label="退单中" value="3"></el-option>
            <el-option label="已取消" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出行状态">
          <el-select v-model="formInline.travel_status" placeholder="请选择">
            <el-option label="未出行" value="0"></el-option>
            <el-option label="行驶中" value="1"></el-option>
            <el-option label="已完成" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发布时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker v-model="formInline.reg_date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="id" label="ID" width="80"></el-table-column>
          <el-table-column prop="ordernum" label="订单号"></el-table-column>

          <el-table-column label="行程信息">
            <template slot-scope="scope">
              <div class="order-code">
                <span class="pl16">起点：{{ scope.row.star_address}}</span><br />
                <span class="pl16">停靠点：
                  <span class="pl16 block"
                    v-for="(item, index) in scope.row.address">{{index+1}}.{{item.m_name}}</span>
                </span><br />
                <span class="pl16">终点：{{ scope.row.end_address }}</span><br />
                <span class="pl16">出发时间：{{ scope.row.star_time }}</span><br />
                <span class="pl16">预计到达时间：{{ scope.row.end_time }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="车辆信息">
            <template slot-scope="scope">
              <div class="order-code" v-for="(item,index) in scope.row.car">
                <span class="pl16 block">车牌号：{{ item.car_number }} &nbsp;&nbsp;&nbsp;<br /> 司机：{{ item.driver_name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="price" label="本次费用"></el-table-column>
          <el-table-column prop="user.nickName" label="发布人"></el-table-column>
          <el-table-column prop="takeruser.nickName" label="接单人"></el-table-column>
          <el-table-column prop="create_time" label="发布时间"></el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <span  class="green block">{{scope.row.status_name}}</span>
              <span  class="green block">{{scope.row.owner_status_name}}</span>
              <span  class="blue block" v-if="scope.row.status==1 && scope.row.owner_status==1">{{scope.row.travel_status_name}}</span>
              </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="160">
            <template slot-scope="scope">
              <el-button @click="detailClick(scope.row)" type="text" size="small" v-auth="'/order/car_order/detail'">
                订单详情</el-button>
              <el-button @click="deleteClick(scope.row)" class="red" type="text" size="small" v-auth="'/order/car_order/delete'">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
          :current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"></el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
  import OrderApi from '@/api/order.js';
  export default {
    components: {
      /*编辑组件*/

    },
    data() {
      return {
        /*是否加载完成*/
        loading: true,
        /*列表数据*/
        tableData: [],
        /*一页多少条*/
        pageSize: 15,
        /*一共多少条数据*/
        totalDataNumber: 0,
        /*当前是第几页*/
        curPage: 1,
        /*横向表单数据模型*/
        formInline: {
          order_no: '',
          status: '',
          travel_status:'',
          owner_status:'',
          reg_date: ''
        },
        /*是否打开添加弹窗*/
        open_add: false,
        /*是否打开编辑弹窗*/
        open_edit: false,
        /*当前编辑的对象*/
        userModel: {},

      };
    },
    created() {
      /*获取列表*/
      this.getTableList();
    },
    methods: {
      /*选择第几页*/
      handleCurrentChange(val) {
        let self = this;
        self.curPage = val;
        self.loading = true;
        self.getTableList();
      },

      /*每页多少条*/
      handleSizeChange(val) {
        this.curPage = 1;
        this.pageSize = val;
        this.getTableList();
      },

      /*获取列表*/
      getTableList() {
        let self = this;
        let Params = self.formInline;
        Params.page = self.curPage;
        Params.list_rows = self.pageSize;
        OrderApi.carOrder(Params, true)
          .then(data => {
            self.loading = false;
            self.tableData = data.data.list.data;
            self.totalDataNumber = data.data.list.total;
          })
          .catch(error => {
            self.loading = false;
          });
      },

      /*搜索查询*/
      onSubmit() {
        let self = this;
        self.curPage = 1;
        self.loading = true;
        let Params = self.formInline;
        self.getTableList();
      },

      /*打开添加*/
      addClick(item) {
        this.userModel = item;
        this.open_add = true;
      },

      /*打开编辑*/
      detailClick(row) {
        let self = this;
        let id = row.id;
        this.$router.push({
          path: '/order/car_order/detail',
          query: {
            id: id
          }
        })
      },
      /*删除用户*/
      deleteClick(row) {
        let self = this;
        self
          .$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          .then(() => {
            self.loading = true;
            OrderApi.deleteOrder(
              {
                id: row.id
              },
              true
            )
              .then(data => {
                self.loading = false;
                if (data.code == 1) {
                  self.$message({
                    message: '恭喜你，订单删除成功',
                    type: 'success'
                  });
                  self.getTableList();
                } else {
                  self.loading = false;
                }
              })
              .catch(error => {
                self.loading = false;
              });
          })
          .catch(() => {
            self.loading = false;
          });
      },

      /*关闭弹窗*/
      closeDialogFunc(e, f) {
        if (f == 'add') {
          this.open_add = e.openDialog;
          if (e.type == 'success') {
            this.getTableList();
          }
        }
        if (f == 'edit') {
          this.open_edit = e.openDialog;
          if (e.type == 'success') {
            this.getTableList();
          }
        }
      }
    }

  };
</script>
<style>
  .block {
    display: block;
  }
</style>
